package wiki.hitime.stl.daq.util;

/**
 * @author zhangdaoping
 * @create 2019-07-10 10:15
 */
public class StrUtils {

    /**
     * 对指定位置字符转换为小写
     *
     * @param sourceStr
     * @param index
     * @return
     */
    public static String toLowerCase(String sourceStr, int index) {
        if (sourceStr == null) {
            throw new NullPointerException();
        }
        if (sourceStr.length() <= index) {
            throw new IndexOutOfBoundsException();
        }
        char[] chars = sourceStr.toCharArray();
        chars[index] = Character.toLowerCase(chars[index]);
        return String.valueOf(chars);
    }

    /**
     * 对指定位置字符转换为大写
     *
     * @param sourceStr
     * @param index
     * @return
     */
    public static String toUpperCase(String sourceStr, int index) {
        if (sourceStr == null) {
            throw new NullPointerException();
        }
        if (sourceStr.length() <= index) {
            throw new IndexOutOfBoundsException();
        }
        char[] chars = sourceStr.toCharArray();
        chars[index] = Character.toUpperCase(chars[index]);
        return String.valueOf(chars);
    }
}
